import java.util.Calendar;
import java.util.Date;


public final class DateHelper
{



    private DateHelper()
    {
    }
    public static DateHelper getInstance()
    {
    return new DateHelper();
    }
    public Date toDate( int year , int month , int date , int hourOfDay , int minute )
    {
        Calendar calendar = Calendar.getInstance();
        calendar.set(year,month,date,hourOfDay,minute);
        calendar.set(Calendar.SECOND,0);
        calendar.set(Calendar.MILLISECOND,0);
        Date date1 = calendar.getTime();
        return date1;
    }
    public Date toDate( int year , int month , int date , int hourOfDay , int minute , int second ) {
        // 可以将 毫秒 部分直接设置为 零
        Calendar calendar = Calendar.getInstance();
        calendar.set(year,month,date,hourOfDay,minute,second);
        calendar.set(Calendar.MILLISECOND,0);
        Date date1 = calendar.getTime();
        return date1;
    }
    public Date toDate( int year , int month , int date , int hourOfDay , int minute , int second , int millis )
    {
        // 自行设计实现过程
        Calendar calendar = Calendar.getInstance();
        calendar.set(year,month,date,hourOfDay,minute,second);
        calendar.set(Calendar.MILLISECOND,millis);
        Date date1 = calendar.getTime();
        return date1;
    }
    public String toString( final Calendar date )
    {
        StringBuilder builder = new StringBuilder();

        int year = date.get( Calendar.YEAR );
        builder.append( year + "年" );

        // 鬼子那边的月份是从 零 开始计数的
        int month = date.get( Calendar.MONTH ) + 1 ;
        builder.append( month + "月" );

        int day = date.get( Calendar.DATE );
        builder.append( day + "日" );

        int hours = date.get( Calendar.HOUR_OF_DAY );
        if( hours < 10 ) {
            builder.append( '0' );
        }
        builder.append( hours + ":" );

        int minutes = date.get( Calendar.MINUTE );
        if( minutes < 10 ) {
            builder.append( '0' );
        }
        builder.append( minutes + ":" );

        int seconds = date.get( Calendar.SECOND );
        if( seconds < 10 ) {
            builder.append( '0' );
        }
        builder.append( seconds + "." );

        int millis = date.get( Calendar.MILLISECOND );
        if (millis < 10){
            builder.append(  '0' );
            builder.append(  '0' );
            if (millis >=10 && millis < 100){
                builder.append(  '0' );
            }
        }
        builder.append( millis );

        String s = builder.toString();
        return s ;
    }

    public String toString ( final Date date ) {

        // 实现思路:

        // 1、获取一个 Calendar 实例
        Calendar calendar=Calendar.getInstance();

        // 2、清空 Calendar 实例的 日历字段值 和 时间值
        calendar.clear();
        // 3、将 参数 date 所表示的瞬间设置到 新创建的 Calendar 实例中
        calendar.setTime(date);
        // 4、调用 toString( Calendar ) 方法获取 Calendar实例 的字符串形式
        String s=toString(calendar);
        // 5、将 Calendar实例 的字符串形式 直接返回即可
        return s;
    }

    public int durationOfDays( Date first , Date second )
    {
     if (first.before( second )==true)
     {
         long l = first.getTime() - second.getTime();
         int o=(int)(l/1000)/60/60/24;
         return o;
     }
            if (first.equals(second))
            {
                return 0;
            }
        long ll=first.getTime() - second.getTime();
        int oo=(int)(ll/1000)/60/60/24;
        return oo;
    }



}